# Build script to generate  documentation without polluting the 
# source tree.
# 
# Author: bastian
###############################################################################

# TODO roxygen fails on many S4 constructs without informative error messages.
# directly use rd until roxygen is fixed.

library(roxygen)

dobus.components.with.roxygen <- "driver"
dobus.components <- c("reporting","flow","tracR") 


BuildDobus <- function(source.dir=".", 
    build.dir=stop("Specify build directory."),
    unlink.target=FALSE) 
{
  if (file.exists(build.dir))
  {
    if (file.info(build.dir)$isdir==FALSE)
    {
      stop(paste(build.dir,"is not a directory."))
    }
  }
  dir.create(build.dir, showWarnings = !unlink.target)
  
  save.wd <- getwd()
  for (component in dobus.components.with.roxygen)
  {
    component.source.dir <- file.path(source.dir, component)
    component.dest.dir <- file.path(build.dir, component)

    print(paste("Setting up",component))
    
    roxygenize(component.source.dir, roxygen.dir=component.dest.dir, copy.package=FALSE, 
        unlink.target=unlink.target)
  }
  
}